package com.xiaoming.mojbackendjudgeservice.listens;


import com.xiaoming.mojbackendjudgeservice.JudgeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class judgeListen {
    private final JudgeService judgeService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.judge.queue",durable = "true"),
            exchange = @Exchange(name = "moj.direct",type = ExchangeTypes.DIRECT),
            key = {"judge"}))
    public void judgeByQuestionSubmitId(Long questionSubmitId)
    {

        System.out.println(questionSubmitId);
        try {
            judgeService.doJudge(questionSubmitId);
            log.info("消息队列启动成功");

        } catch (Exception e) {
            log.error("消息队列启动失败", e);
        }


    }
}
